package com.itheima.health.controller;

import com.itheima.health.resource.entity.Result;
import com.itheima.health.resource.pub.MessageConstant;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {
    /**
     * 获取用户登录信息   session
     * @param authentication
     * @return
     */
    @RequestMapping("getUserName.do")
    public  Result getUserName(Authentication authentication){
        try {
            String name = authentication.getName();

//            SecurityContextHolder.getContext().getAuthentication().getName()

            return  new Result(true, MessageConstant.GET_USERNAME_SUCCESS,name);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.GET_USERNAME_FAIL);
        }
    }
}
